import re


def getUrl_from_content(content_head):
    # content_head = f.read(500)
    pattern = re.compile('url: (.*?)\s')
    url_list = pattern.findall(content_head)
    return url_list[0] if len(url_list) > 0 else ""

def getDatetime_from_content(content_head):
    pattern = re.compile('saved date: (.*?)\n')
    url_list = pattern.findall(content_head)
    return url_list[0] if len(url_list) > 0 else ""

def getTitle_from_path(path):
    pattern = re.compile('^(.*?)(?=__)')
    title_list = pattern.findall(path)
    return title_list[0] if len(title_list) > 0 else "no title"

def getHash_from_path(path):
    pattern = re.compile('__(.*?)\\.html')
    hash_list = pattern.findall(path)
    return hash_list[0] if len(hash_list) > 0 else ""

def getHash_from_video_path(path):
    pattern = re.compile('__(.*?)\\.mp4')
    hash_list = pattern.findall(path)
    return hash_list[0] if len(hash_list) > 0 else ""